<--- %%NOBANNER%% --> _rancau.sas
 BackForward

/*-------------------<-- Start of Description -->--------------------\
| Generate random variate from a Cauchy distribution                 |
|--------------------<--- End of Description -->---------------------|
|--------------------------------------------------------------------|
|--------------<--- Start of Files or Arguments Needed -->-----------|
| Arguments Need:                                                    |
|      seed - seed; Required, default is the current system time;    |
|      var  - the variable to save the generated random variates;    |
|      mean - the mean of the normal distribution;                   |
|      std  - the std of the distribution;                           |
|      temp - the temporary variable to update the seed;             |
|             default is _rancau0_;                                  |
|---------------<--- End of Files or Arguments Needed -->------------|
|--------------------------------------------------------------------|
|----------------<--- Start of Example and Usage -->-----------------|
|Example                                                             |
|   data one;                                                        |
|      do i=1 to 20;                                                 |
|      x=%_rancau(seed=1, mean=10, std=5);                           |
|      z=%_rancau(seed=1);                                           |
|      %_rancau(var=y, seed=1, mean=10, std=5);                      |
|      output;                                                       |
|      end;                                                          |
|   run; %print(one);                                                |
|Usage: %_rancau(seed=%sysfunc(datetime(), 15.), var=, mean=, std=,  |
|                temp=_rancau0_);                                    |
\-------------------<--- End of Example and Usage -->---------------*/
%macro _rancau(seed=%sysfunc(datetime(), 15.), var=, mean=, std=, 
               temp=_rancau0_);
/*--------------------------------------------\
| Author:  Duo Zhou;                          |
| Created: 3-22-2002 6:30pm;                  |
| Purpose: Random Cauchy Generator;           |
\--------------------------------------------*/
%if (%quote(&seed) eq) %then %do;
   %put ==> Error: This is not a valid seed!; 
   %if (%length(&var)) %then %do; &var=.; %end;
   %else %do; .;%end;
   %goto finish;
%end;
%else %do;
   %if (%length(&var)) %then %do;
      %if (not %sysfunc(rxmatch(%sysfunc(rxparse(_|.|$a|$A|$w)),&seed))) %then %do;
         drop &temp;
         retain &temp &seed;
         %let seed=&temp;
      %end;
      call rancau(&seed, &var);
      %if (%length(&mean.&std)) %then &var=&var;
   %end;
   %else rancau(&seed);
   %if (%length(&std))  %then *&std;
   %if (%length(&mean)) %then +&mean;
%end;
%finish:
%mend _rancau;